﻿IF EXISTS (SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = 'OTCotizacionInsert')
	BEGIN
		DROP  Procedure  OTCotizacionInsert
	END
GO


CREATE PROCEDURE [dbo].[OTCotizacionInsert] 	
	(			
		@EmpresaId				AS INT,		
		@NumeroOT				AS VARCHAR(30),
		@ArticuloId				AS VARCHAR(13) = NULL ,
		@ClienteId				AS VARCHAR(12) = NULL,
		@FechaEntrega			AS DATETIME	= NULL,	
		@Referencia				AS VARCHAR(500) = NULL,
		@VendedorId				AS INT = NULL,	
		@PruebaColor			AS BIT = NULL,
		@Laser					AS BIT = NULL,
		@TrabajoNuevo			AS BIT = NULL,
		@ReimpresionCambios		AS BIT = NULL,
		@ReimpresionExacta		AS BIT = NULL,
		@Cantidad				AS DECIMAL(10,2) = NULL,		
		@TamanoFinal			AS VARCHAR(100) = NULL,		
		@Impresion2Lados		AS BIT = NULL,
		@FullColor				AS BIT = NULL,
		@DosColores				AS BIT = NULL,
		@UnColor				AS BIT = NULL,
		@Pantone				AS BIT = NULL,
		@Otros					AS BIT = NULL,
		@AcabadosFinales		AS VARCHAR(500) = NULL,
		@Comentarios			AS VARCHAR(500) = NULL,				
		@Factura				AS VARCHAR(100) = NULL,
		@HorasAcabados			AS DECIMAL(10,2) = NULL,
		@HorasPrensas			AS DECIMAL(10,2) = NULL,
		@GastosIndirectos		AS DECIMAL(10,2) = NULL,
		@CantidadDommies		AS INT = NULL,
		@Observaciones			AS VARCHAR(500) = NULL,
		@Boleta					AS VARCHAR(50) = NULL,
		@VistoBuenoMaquina		AS BIT = NULL,
		@DibujoMontaje			AS VARCHAR(100) = NULL,
		@EstadoId				AS INT = NULL		
		
	)	
AS
BEGIN	
	SET NOCOUNT ON
	DECLARE @id INT
	
	INSERT INTO Lit_OT 
			(EmpresaId, NumeroOT, ArticuloId, ClienteId, 
			 FechaEntrega, FechaIngreso, Referencia, VendedorId, 
			 PruebaColor, Laser, TrabajoNuevo,
			 ReimpresionCambios, ReimpresionExacta, Cantidad, TamanoFinal,
			 Impresion2Lados, FullColor, DosColores, UnColor, 
			 Pantone, Otros, AcabadosFinales, Comentarios, Factura,		
			 HorasAcabados, HorasPrensas, GastosIndirectos, 
			 CantidadDommies, Observaciones, Boleta, VistoBuenoMaquina, DibujoMontaje, EstadoId)
		VALUES 
			(@EmpresaId, @NumeroOT, @ArticuloId, @ClienteId, 
			 @FechaEntrega, GETDATE(), @Referencia, @VendedorId, 
			 @PruebaColor, @Laser, @TrabajoNuevo,
			 @ReimpresionCambios, @ReimpresionExacta, @Cantidad, @TamanoFinal,
			 @Impresion2Lados, @FullColor, @DosColores, @UnColor, 
			 @Pantone, @Otros, @AcabadosFinales, @Comentarios, @Factura,		
			 @HorasAcabados, @HorasPrensas, @GastosIndirectos, 
			 @CantidadDommies, @Observaciones, @Boleta, @VistoBuenoMaquina, @DibujoMontaje, @EstadoId)
		
		SELECT @id = SCOPE_IDENTITY()
		
		SELECT	Id, EmpresaId, NumeroOT, ArticuloId As ProductoId, ClienteId, 
			 FechaEntrega, FechaIngreso, Referencia, VendedorId, 
			 PruebaColor, Laser, TrabajoNuevo,
			 ReimpresionCambios, ReimpresionExacta, Cantidad, TamanoFinal,
			 Impresion2Lados, FullColor, DosColores, UnColor, 
			 Pantone, Otros, AcabadosFinales, Comentarios, Factura,		
			 HorasAcabados, HorasPrensas, GastosIndirectos, 
			 CantidadDommies, Observaciones, Boleta, VistoBuenoMaquina, DibujoMontaje, EstadoId
		FROM Lit_OT
		WHERE Id = @id
		
	SET NOCOUNT OFF
END
GO 